//package ;
//
//import org.apache.shardingsphere.api.sharding.standard.PreciseShardingAlgorithm;
//import org.apache.shardingsphere.api.sharding.standard.PreciseShardingValue;
//import org.apache.shardingsphere.api.sharding.standard.RangeShardingAlgorithm;
//import org.apache.shardingsphere.api.sharding.standard.RangeShardingValue;
//import org.springframework.util.CollectionUtils;
//
//import java.util.ArrayList;
//import java.util.Collection;
//import java.util.Date;
//import java.util.List;
//
//public class MonthShardingAlgorithm implements PreciseShardingAlgorithm<Date>, RangeShardingAlgorithm<Date> {
//
//    @Override
//    public String doSharding(Collection<String> availableTargetNames
//            , PreciseShardingValue<Date> shardingValue) {
//        int month = DateUtil.month(shardingValue.getValue());
//        String tableName = shardingValue.getLogicTableName() + "_" + month;
//        if (availableTargetNames.contains(tableName)) {
//            return tableName;
//        }
//        throw new UnsupportedOperationException(String.format(
//                "route %s unsupported, check sharding config"
//                , tableName
//        ));
//    }
//
//    @Override
//    public Collection<String> doSharding(Collection<String> availableTargetNames
//            , RangeShardingValue<Date> shardingValue) {
//        List<String> tableNameRange = new ArrayList<>();
//        int lower = DateUtil.month(shardingValue.getValueRange().lowerEndpoint());
//        int upper = DateUtil.month(shardingValue.getValueRange().upperEndpoint());
//        int curr = lower;
//        boolean isBreak;
//        do {
//            String tableName = shardingValue.getLogicTableName() + "_" + curr;
//            if (availableTargetNames.contains(tableName)) {
//                tableNameRange.add(tableName);
//            }
//            if (++curr > 12 && upper < lower) {
//                curr = 1;
//            }
//            isBreak = upper >= lower ? curr > upper : curr > upper & curr < lower;
//        } while (!isBreak);
//        if (CollectionUtils.isEmpty(tableNameRange)) {
//            throw new UnsupportedOperationException(String.format(
//                    "route %s - %s unsupported, check sharding config"
//                    , lower, upper
//            ));
//        }
//        return tableNameRange;
//    }
//
////    public static void main(String[] args) {
////        List<String> tableNameRange = new ArrayList<>();
////        int lower = 1;
////        int upper = 1;
////        int curr = lower;
////        boolean isBreak;
////        do {
////            String tableName = "tableName_" + curr;
////            tableNameRange.add(tableName);
////            if (++curr > 12 && upper < lower) {
////                curr = 1;
////            }
////            isBreak = upper >= lower ? curr > upper : curr > upper & curr < lower;
////        } while (!isBreak);
////        System.out.println(tableNameRange);
////    }
//
//}
//
//
